package com.ruoyi.web.controller.demo;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.ProjectInfo;
import com.ruoyi.service.ProjectInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 项目Controller
 * 
 * @author leo
 * @date 2021-07-27
 */
@RestController
@RequestMapping("/basic/projectInfo")
public class ProjectInfoController extends BaseController
{
    @Autowired
    private ProjectInfoService projectInfoService;

    /**
     * 查询项目列表
     */
    @PreAuthorize("@ss.hasPermi('basic:projectInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectInfo projectInfo)
    {
        startPage();
        List<ProjectInfo> list = projectInfoService.selectProjectInfoList(projectInfo);
        return getDataTable(list);
    }

    /**
     * 导出项目列表
     */
    @PreAuthorize("@ss.hasPermi('basic:projectInfo:export')")
    @Log(title = "项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ProjectInfo projectInfo)
    {
        List<ProjectInfo> list = projectInfoService.selectProjectInfoList(projectInfo);
        ExcelUtil<ProjectInfo> util = new ExcelUtil<ProjectInfo>(ProjectInfo.class);
        return util.exportExcel(list, "项目数据");
    }

    /**
     * 获取项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:projectInfo:query')")
    @GetMapping(value = "/{prjId}")
    public AjaxResult getInfo(@PathVariable("prjId") Long prjId)
    {
        return AjaxResult.success(projectInfoService.getById(prjId));
    }

    /**
     * 新增项目
     */
    @PreAuthorize("@ss.hasPermi('basic:projectInfo:add')")
    @Log(title = "项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectInfo projectInfo)
    {
        return toAjax(projectInfoService.save(projectInfo));
    }

    /**
     * 修改项目
     */
    @PreAuthorize("@ss.hasPermi('basic:projectInfo:edit')")
    @Log(title = "项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectInfo projectInfo)
    {
        return toAjax(projectInfoService.updateById(projectInfo));
    }

    /**
     * 删除项目
     */
    @PreAuthorize("@ss.hasPermi('basic:projectInfo:remove')")
    @Log(title = "项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{prjIds}")
    public AjaxResult remove(@PathVariable Long[] prjIds)
    {
        List<String> idList = Arrays.stream(prjIds).map(String::valueOf).collect(Collectors.toList());
        return toAjax(projectInfoService.removeByIds(idList));
    }
}